package org.dromara.manu.controller;

import java.util.List;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.manu.domain.vo.ScreenVo;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.manu.domain.vo.ManuPubToolScreenVo;
import org.dromara.manu.domain.bo.ManuPubToolScreenBo;
import org.dromara.manu.service.IManuPubToolScreenService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 车间屏幕管理单
 *
 * @author Bin Liu
 * @date 2024-07-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/manu/pubToolScreen")
public class ManuPubToolScreenController extends BaseController {

    private final IManuPubToolScreenService manuPubToolScreenService;

    /**
     * 查询车间屏幕管理单列表
     */
    @SaCheckPermission("manu:pubToolScreen:list")
    @GetMapping("/list")
    public TableDataInfo<ManuPubToolScreenVo> list(ManuPubToolScreenBo bo, PageQuery pageQuery) {
        return manuPubToolScreenService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出车间屏幕管理单列表
     */
    @SaCheckPermission("manu:pubToolScreen:export")
    @Log(title = "车间屏幕管理单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ManuPubToolScreenBo bo, HttpServletResponse response) {
        List<ManuPubToolScreenVo> list = manuPubToolScreenService.queryList(bo);
        ExcelUtil.exportExcel(list, "车间屏幕管理单", ManuPubToolScreenVo.class, response);
    }

    /**
     * 获取车间屏幕管理单详细信息
     *
     * @param id 主键
     */
    @SaIgnore
    @SaCheckPermission("manu:pubToolScreen:query")
    @GetMapping("/{id}")
    public R<ManuPubToolScreenVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(manuPubToolScreenService.queryById(id));
    }

    /**
     * 新增车间屏幕管理单
     */
    @SaCheckPermission("manu:pubToolScreen:add")
    @Log(title = "车间屏幕管理单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ManuPubToolScreenBo bo) {
        return toAjax(manuPubToolScreenService.insertByBo(bo));
    }

    /**
     * 修改车间屏幕管理单
     */
    @SaCheckPermission("manu:pubToolScreen:edit")
    @Log(title = "车间屏幕管理单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ManuPubToolScreenBo bo) {
        return toAjax(manuPubToolScreenService.updateByBo(bo));
    }

    /**
     * 删除车间屏幕管理单
     *
     * @param ids 主键串
     */
    @SaCheckPermission("manu:pubToolScreen:remove")
    @Log(title = "车间屏幕管理单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(manuPubToolScreenService.deleteWithValidByIds(List.of(ids), true));
    }

    @SaIgnore
    @GetMapping("/screenInfoById/{id}")
    public R<ScreenVo> getScreenByScreenId(@PathVariable Long id){

        return R.ok(manuPubToolScreenService.getScreenByScreenId(id));
    }

    @SaIgnore
    @GetMapping("/showScreenList")
    public TableDataInfo<ManuPubToolScreenVo> showScreenList(ManuPubToolScreenBo bo) {
        PageQuery pageQuery = new PageQuery();
        pageQuery.setPageNum(1);
        pageQuery.setPageSize(1000);
        return manuPubToolScreenService.queryPageList(bo, pageQuery);
    }
}
